﻿using Face8280WebSocketServer.Command;
using DoNetDrive.Core.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Face8280WebSocketServer.Utility;
using Newtonsoft.Json;

namespace Face8280WebSocketServer.Command.Person
{
    public class AddPerson : JsonCommand
    {

        Person_DTO _Person;
        public AddPerson(INCommandDetail cd, Person_DTO par) : base(cd, par)
        {
            _Person = par;
            //  CheckValue(par);
            mJsonResult = (s) => _Result = new AddPersonResult(s);
        }
        protected override void CreatePacket()
        {
            if (_Person.FeatureData != null && _Person.FeatureData.Count > 0)
            {
                _Person.FeatureData.Sort((x, y) => x.Num.CompareTo(y.Num));
                List<byte> Datas = new();
                foreach (var item in _Person.FeatureData)
                {
                    if (item.DataType == Models.FeatureDataType.Stream)
                    {
                        Datas.AddRange(item.BinaryData);
                    }
                }
                var sJson = JsonConvert.SerializeObject(mSendObject, setting);
                _Packet = new JsonPacket(sJson, Datas.ToArray());
                _ProcessStep = 1;
            }
            else
            {
                base.CreatePacket();
            }

        }
    }
}
